export default function (vue) {
  let direct = {
    shape: {
      mounted: (el, binding, vnode) => {
        const isSupported = navigator.share && binding.value;

        el.style.cursor = isSupported ? 'pointer' : 'not-allowed';
        el.title = isSupported ? '点击分享内容' : '当前浏览器不支持分享';
        el.addEventListener('click', async () => {
          try {
            if (!isSupported) {
              alert('0.o? 点击右上角分享');
              return
            }
            await navigator.share({
              title: binding.value.title || document.title,
              text: binding.value.text || '',
              url: binding.value.url || window.location.href
            });

            binding.arg && app.config.globalProperties[binding.arg]?.();
          } catch (error) {
            // 错误处理（用户取消分享不报错）
            if (error.name !== 'AbortError') {
              console.error('分享失败:', error);
            }
          }
        });
      }
    }
  }
  for (let key in direct) {
    vue.directive(key, direct[key]);
  }
}